package com.ruoyi.workbench.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.workbench.domain.WorkTarget;
import com.ruoyi.workbench.service.IWorkTargetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 年度考核指标Controller
 * 
 * @author Guojl
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/target/target")
public class WorkTargetController extends BaseController
{
    @Autowired
    private IWorkTargetService workTargetService;

    /**
     * 查询年度考核指标列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WorkTarget workTarget)
    {
        startPage();
        List<WorkTarget> list = workTargetService.selectWorkTargetList(workTarget);
        return getDataTable(list);
    }

    /**
     * 导出年度考核指标列表
     */
    @Log(title = "年度考核指标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkTarget workTarget)
    {
        List<WorkTarget> list = workTargetService.selectWorkTargetList(workTarget);
        ExcelUtil<WorkTarget> util = new ExcelUtil<WorkTarget>(WorkTarget.class);
        util.exportExcel(response, list, "年度考核指标数据");
    }

    /**
     * 获取年度考核指标详细信息
     */
    @GetMapping(value = "/{targetId}")
    public AjaxResult getInfo(@PathVariable("targetId") Long targetId)
    {
        return success(workTargetService.selectWorkTargetByTargetId(targetId));
    }

    /**
     * 新增年度考核指标
     */
    @Log(title = "年度考核指标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkTarget workTarget)
    {
        return toAjax(workTargetService.insertWorkTarget(workTarget));
    }

    /**
     * 修改年度考核指标
     */
    @Log(title = "年度考核指标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkTarget workTarget)
    {
        return toAjax(workTargetService.updateWorkTarget(workTarget));
    }

    /**
     * 删除年度考核指标
     */
    @Log(title = "年度考核指标", businessType = BusinessType.DELETE)
	@DeleteMapping("/{targetIds}")
    public AjaxResult remove(@PathVariable Long[] targetIds)
    {
        return toAjax(workTargetService.deleteWorkTargetByTargetIds(targetIds));
    }
}
